package cn.edu.hunau.pm.advice;

import cn.edu.hunau.pm.common.R;
import cn.edu.hunau.pm.exception.BusinessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**统一异常处理类**/
@ControllerAdvice//全局处理异常的切面
public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(BusinessException.class)//在业务异常上响应，监听BusinessException
    public R error(BusinessException e)
    {
        e.printStackTrace();
        return R.error().code(e.getCode()).message("advice:"+e.getMessage());
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)//在业务异常上响应，监听BusinessException
    public R error(Exception e)
    {
        e.printStackTrace();

        return R.error().code(400444).message("未知错误");
    }
}
